<?php
/**
 * Created by PhpStorm.
 * User: xiaoFeng
 * Date: 2019/1/15
 * Time: 13:50
 */
namespace app\portal\controller;

use cmf\controller\AdminBaseController;
use app\portal\model\RecruitmentModel ;
use think\Db;


class  AdminRecruitController extends AdminBaseController
{
    public function index()
    {
        $recruitmentModel = new RecruitmentModel();


        $lists = $recruitmentModel->order('id','desc')->paginate(20);

        $this->assign("recruitmentList", $lists);
        $this->assign('page', $lists->render());
        return $this->fetch();
    }

    /*
     * 添加招聘
     */
    public function add()
    {

        return $this->fetch();
    }


    /*
     * 提交添加招聘表单
     */
    public function addPost(){
        $param = $this->request->param();
        $param['post']['content'] = htmlspecialchars_decode($param['post']['content'] );
        $result = Db::name('recruitment')->insertAll($param);
        if($result){
            $this->success('添加成功','AdminRecruit/index');
        }else{
            $this->error('添加失败','');
        }
    }

    /*
     * 删除数据
     */
    public function delete()
    {
        $param = $this->request->param();



//        if($param['id']>0){
//            Db::name('recruitment')->where('id',$param['id'])->delete();
//        }
//        $this->success("删除成功！", '');

        if(isset($param['id'])){
            Db::name('recruitment')->where('id',$param['id'])->delete();
            $this->success("删除成功！", '');
        }

        if (isset($param['ids'])) {
            $ids     = $this->request->param('ids/a');
            Db::name('recruitment')->where(['id' => ['in', $ids]])->delete();
            $this->success("删除成功！", '');
        }
    }

   /*
    * 编辑招聘信息
    */
   public function edit()
   {

       $id = $this->request->param('id', 0, 'intval');
       $post            = Db::name('recruitment')->where('id', $id)->find();
       $this->assign('post', $post);
       return $this->fetch();


   }

   /*
    * 更新招聘信息
    */

   public function update()
   {
       $data = $this->request->param();
       $data['post']['content'] = htmlspecialchars_decode($data['post']['content']);
       Db::name("recruitment")->where(["id" => $data['post']['id']])->update($data['post']);
       $this->success('修改成功','');
   }
}






